package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.IVL_TS;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;

import java.io.Serializable;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;



@Entity
@NamedQuery(name = "Supply.findAll", query = "select o from Supply o")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("SPLY")
public class Supply extends Act implements Serializable {
    
//    public IVL_TS expectedUseTime;
//    public PQ quantity;
    
    public Supply() throws Hl7Exception {
    }
    

    public void setExpectedUseTime(IVL_TS expectedUseTime) {
        this.setSpExpectUseStartDateTs( new Timestamp(expectedUseTime.low().toDate().getTime())); 
        this.setSpExpectUseEndDateTs( new Timestamp(expectedUseTime.high().toDate().getTime()));
        this.setSpExpectUseDateTxt( expectedUseTime.literal().toString());
        PQ pq = (PQ)expectedUseTime.width();
        this.setSpExpectUseIvlDateTxt( pq.value().literal().toString());
        this.setSpExpectUseIvlUomCode(pq.unit().code().toString()); 
    }

    public IVL_TS getExpectedUseTime() throws Hl7Exception {
        return DataTypeUtil.getIVL_TS(this.getSpExpectUseStartDateTs(), this.getSpExpectUseEndDateTs(), this.getSpExpectUseIvlDateTxt(), this.getSpExpectUseIvlUomCode(), null);  
    }

    public void setQuantity(PQ quantity) {
//        this.quantity = quantity;
    }

    public PQ getQuantity() {
        return null;
    }
    
    //Supply
        @Column(name = "SP_EXPECT_USE_DATE_TXT")    protected String spExpectUseDateTxt;
        @Column(name = "SP_EXPECT_USE_END_DATE_TS")    protected Timestamp spExpectUseEndDateTs;
        @Column(name = "SP_EXPECT_USE_IVL_DATE_TXT")    protected String spExpectUseIvlDateTxt;
        @Column(name = "SP_EXPECT_USE_IVL_UOM_CODE")    protected String spExpectUseIvlUomCode;
        @Column(name = "SP_EXPECT_USE_START_DATE_TS")    protected Timestamp spExpectUseStartDateTs;
        @Column(name = "SP_QTY_TXT")    protected String spQtyTxt;
        @Column(name = "SP_QTY_UOM_CODE")    protected String spQtyUomCode;
        
    protected String getSpExpectUseDateTxt() {
        return spExpectUseDateTxt;
    }

    protected void setSpExpectUseDateTxt(String spExpectUseDateTxt) {
        this.spExpectUseDateTxt = spExpectUseDateTxt;
    }

    protected Timestamp getSpExpectUseEndDateTs() {
        return spExpectUseEndDateTs;
    }

    protected void setSpExpectUseEndDateTs(Timestamp spExpectUseEndDateTs) {
        this.spExpectUseEndDateTs = spExpectUseEndDateTs;
    }

    protected String getSpExpectUseIvlDateTxt() {
        return spExpectUseIvlDateTxt;
    }

    protected void setSpExpectUseIvlDateTxt(String spExpectUseIvlDateTxt) {
        this.spExpectUseIvlDateTxt = spExpectUseIvlDateTxt;
    }

    protected String getSpExpectUseIvlUomCode() {
        return spExpectUseIvlUomCode;
    }

    protected void setSpExpectUseIvlUomCode(String spExpectUseIvlUomCode) {
        this.spExpectUseIvlUomCode = spExpectUseIvlUomCode;
    }

    protected Timestamp getSpExpectUseStartDateTs() {
        return spExpectUseStartDateTs;
    }

    protected void setSpExpectUseStartDateTs(Timestamp spExpectUseStartDateTs) {
        this.spExpectUseStartDateTs = spExpectUseStartDateTs;
    }

    protected String getSpQtyTxt() {
        return spQtyTxt;
    }

    protected void setSpQtyTxt(String spQtyTxt) {
        this.spQtyTxt = spQtyTxt;
    }

    protected String getSpQtyUomCode() {
        return spQtyUomCode;
    }

    protected void setSpQtyUomCode(String spQtyUomCode) {
        this.spQtyUomCode = spQtyUomCode;
    }
        
}
